2 Problem: 11517 - Exact Change
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
29 #define D(x) cout << #x " is " << x << endl
31 const int S
= 10005, N
= 105, oo
= INT_MAX
/ 4;
33 int dp
[2][S
*N
+1], c
[N
];
36 dp[i][j] = Mínima cantidad de monedas para formar j pesos
37 utilizando las primeras i monedas. (0 <= i <= n)
53 c
[0] = oo
; // Don't fuck
57 for (int i
=1; i
<=n
; ++i
){
61 if (c
[i
] >= price
) cota
= min(cota
, c
[i
]);
64 cota
= min(cota
, sum
);
65 //sum = min(sum, price);
68 for (int j
=1; j
<= cota
; ++j
) dp
[0][j
] = oo
;
70 for (int i
=1; i
<=n
; ++i
){
71 for (int j
=0; j
<=cota
; ++j
){
72 dp
[i
%2][j
] = dp
[(i
+1)%2][j
];
74 dp
[i
%2][j
] = min(dp
[i
%2][j
], dp
[(i
+1)%2][j
-c
[i
]] + 1);
80 for (int i=0; i<=n; ++i){
81 for (int j=0; j<=sum; ++j){
82 printf("%10d ", dp[i][j]);
88 for (int j
=price
; /*j <= sum*/; ++j
){
90 cout
<< j
<< " " << dp
[n
%2][j
] << endl
;